package com.hourse.app.controller.rms;

import com.hourse.app.service.ExternalAccountService;
import com.hourse.app.service.PlatformAccountService;
import com.hourse.app.vo.rms.BingExternalAccountVo;
import com.hourse.app.vo.web.BalanceRetVo;
import com.hourse.app.vo.web.OrdersRetVo;
import com.hourse.okx.config.APIConfiguration;
import com.hourse.platform.vo.PageData;
import com.hourse.platform.vo.ResultMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @作者：lichenguang
 * @描述：【账户信息】
 * @创建：2022/2/24 18:03
 */
@RestController
@Slf4j
@Api(tags = "后管-三方账户服务")
@RequestMapping("rms/account")
public class RmsAccountController {

  @Autowired
  private ExternalAccountService externalAccountService;

  @Autowired
  private PlatformAccountService platformAccountService;

  @ApiOperation(value = "查看绑定三方账号信息列表")
  @SneakyThrows
  @GetMapping(value = "list")
  public PageData list(@RequestParam(required = false) String userId) {

    return new ResultMsg(externalAccountService.list(userId));
  }

  @ApiOperation(value = "绑定三方账号信息")
  @SneakyThrows
  @PostMapping(value = "binding")
  public PageData list(@RequestBody BingExternalAccountVo vo) {

    externalAccountService.binding(vo);

    //vo.setIp(IpUtils.getIp());
    return vo.SUCCESS();
  }

  @ApiOperation(value = "三方账号启用禁用")
  @SneakyThrows
  @GetMapping(value = "disabled")
  public PageData disabled(@RequestParam(required = false) String id, @RequestParam(required = false) String isUse) {

    externalAccountService.disabled(id, isUse);

    return new PageData().SUCCESS();
  }

  @ApiOperation(value = "删除绑定三方账号信息")
  @SneakyThrows
  @GetMapping(value = "delete")
  public PageData delete(@RequestParam(required = false) String id) {

    externalAccountService.delete(id);

    return new PageData().SUCCESS();
  }

  @ApiOperation(value = "删除绑定三方账号信息")
  @SneakyThrows
  @GetMapping(value = "connectTest")
  public PageData connectTest(@RequestParam(required = false) String platformId) {

    externalAccountService.connectTest(platformId);

    return new PageData().SUCCESS();
  }

  @ApiOperation(value = "查询-当前委托订单")
  @SneakyThrows
  @GetMapping(value = "findNowOrders")
  public PageData findNowOrders(@RequestParam(required = false) String userId) {

    APIConfiguration config = platformAccountService.getConfig(userId);
    List<OrdersRetVo> list = platformAccountService.findNowOrders(config, "");

    return new ResultMsg<>(list);
  }

  @ApiOperation(value = "查询-历史委托")
  @SneakyThrows
  @GetMapping(value = "findHistoryOrders")
  public PageData findHistoryOrders(@RequestParam(required = false) String userId) {

    APIConfiguration config = platformAccountService.getConfig(userId);
    List<OrdersRetVo> list = platformAccountService.findHistoryOrders(config, "");

    return new ResultMsg<>(list);
  }

  @ApiOperation(value = "查询-资产(余额)")
  @SneakyThrows
  @GetMapping(value = "findBalance")
  public PageData findBalance(@RequestParam(required = false) String userId) {

    APIConfiguration config = platformAccountService.getConfig(userId);
    List<BalanceRetVo> balance = platformAccountService.findBalance(config, "");

    return new ResultMsg<>(balance);
  }

}
